﻿using Currency.Infra.Core.Web;
using Currency.WebApi.Shared.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Currency.WebApi.Shared.Extension
{
    public partial class ServicesRegister
    {
        protected readonly IConfiguration _configuration;
        protected readonly IServiceCollection _services;
        protected readonly IHostEnvironment _environment;
        protected readonly IServiceInfo _serviceInfo;

        /// <summary>
        /// 服务注册与系统配置
        /// </summary>
        /// <param name="configuration"><see cref="IConfiguration"/></param>
        /// <param name="services"><see cref="IServiceInfo"/></param>
        /// <param name="environment"><see cref="IHostEnvironment"/></param>
        /// <param name="serviceInfo"><see cref="IServiceInfo"/></param>
        public ServicesRegister(IConfiguration configuration
            , IServiceCollection services
            , IHostEnvironment environment
            , IServiceInfo serviceInfo)
        {
            _configuration = configuration;
            _services = services;
            _environment = environment;
            _serviceInfo = serviceInfo;
        }

        /// <summary>
        /// 注册配置类到IOC容器
        /// </summary>
        public virtual void Configure()
        {
            _services.Configure<JwtConfig>(_configuration.GetJWTSection());
            _services.Configure<MysqlConfig>(_configuration.GetMysqlSection());
        }
    }
}
